/*
    Copyright 2013 Jonathan Kaschak

    This file is part of TerraTamper.

    TerraTamper is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    TerraTamper is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with TerraTamper.  If not, see <http://www.gnu.org/licenses/>.
*/

package Packets;

import static Main.TerrariaProtocol.*;

public class ProjectileUpdate {
    public static int packet_id = 27;
    
    static byte[] packet = {41, 0, 0, 0, 27, 1, 0, 9, -36, 2, 71, 0, -104, -108, 69, 22, -103, 58, -63, 52, -27, 52, 64, 0, 0, -48, 64, 100, 0, 1, -124, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 0, 0, };
    static int projectile_id = 5;
    static int position_x = 7;
    static int position_y = 11;
    static int velocity_x = 15;
    static int velocity_y = 19;
    static int knockback = 23;
    static int damage = 27;
    static int owner = 29;
    static int type = 30;
    static int ai = 32;
    
    public static byte[] CreateProjectile(int in_projectile_id, int in_position_x, int in_position_y, int in_velocity_x, int in_velocity_y, int in_knockback, int in_damage, int in_owner, int in_type, int in_ai){
        byte[] data = packet;
        
        byte[] temp = int162byte(in_projectile_id);
            data[projectile_id] = temp[0];
            data[projectile_id+1] = temp[1];
        
        temp = int322byte(in_position_x);
            data[position_x] = temp[0];
            data[position_x+1] = temp[1];
            data[position_x+2] = temp[2];
            data[position_x+3] = temp[3];
       
        temp = int322byte(in_position_y);
            data[position_y] = temp[0];
            data[position_y+1] = temp[1];
            data[position_y+2] = temp[2];
            data[position_y+3] = temp[3];
            
        temp = int322byte(in_velocity_x);
            data[velocity_x] = temp[0];
            data[velocity_x+1] = temp[1];
            data[velocity_x+2] = temp[2];
            data[velocity_x+3] = temp[3];
            
        temp = int322byte(in_velocity_y);
            data[velocity_y] = temp[0];
            data[velocity_y+1] = temp[1];
            data[velocity_y+2] = temp[2];
            data[velocity_y+3] = temp[3];
            
        temp = int322byte(in_knockback);
            data[knockback] = temp[0];
            data[knockback+1] = temp[1];
            data[knockback+2] = temp[2];
            data[knockback+3] = temp[3];
            
        temp = int162byte(in_damage);
            data[damage] = temp[0];
            data[damage+1] = temp[1];
            
        data[owner] = (byte)in_owner;
        
        temp = int162byte(in_type);
            data[type] = temp[0];
            data[type+1] = temp[1];
        
        temp = int322byte(in_ai);
            data[ai] = temp[0];
            data[ai+1] = temp[1];
            data[ai+2] = temp[2];
            data[ai+3] = temp[3];
        return data;
    }
    public static int GetProjectileID(byte[] data) {
        return data[projectile_id];
    }
    public static int GetPositionX(byte[] data) {
        return byte2int32(data[position_x],
                          data[position_x+1],
                          data[position_x+2],
                          data[position_x+3]);
    }
    public static int GetPositionY(byte[] data) {
        return byte2int32(data[position_y],
                          data[position_y+1],
                          data[position_y+2],
                          data[position_y+3]);
    }
    public static int GetVelocityX(byte[] data) {
        return byte2int32(data[velocity_x],
                          data[velocity_x+1],
                          data[velocity_x+2],
                          data[velocity_x+3]);
    }
    public static int GetVelocityY(byte[] data) {
        return byte2int32(data[velocity_y],
                          data[velocity_y+1],
                          data[velocity_y+2],
                          data[velocity_y+3]);
    }
    public static int GetKnockback(byte[] data) {
        return byte2int32(data[knockback],
                          data[knockback+1],
                          data[knockback+2],
                          data[knockback+3]);
    }
    public static int GetDamage(byte[] data) {
        return byte2int16(data[damage],
                          data[damage+1]);
    }
    public static int GetOwner(byte[] data) {
        return data[owner];
    }
    public static int GetType(byte[] data) {
        return byte2int16(data[type],
                          data[type+1]);
    }
    public static int GetAI(byte[] data) {
        return byte2int32(data[ai],
                          data[ai+1],
                          data[ai+2],
                          data[ai+3]);
    }
}
